package com.yida.gwj.config.service.impl;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.yida.common.core.utils.DateUtils;
import com.yida.common.security.utils.SecurityUtils;
import com.yida.gwj.config.domain.GwjAttachmentConfig;
import com.yida.gwj.config.domain.dto.GwjAttachmentConfigDTO;
import com.yida.gwj.config.domain.request.GwjAttachmentConfigRequest;
import com.yida.gwj.config.mapper.GwjAttachmentConfigMapper;
import com.yida.gwj.config.service.IGwjAttachmentConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 附件配置Service业务层处理
 *
 * @author ruoyi
 * @date 2023-04-19
 */
@Service
public class GwjAttachmentConfigServiceImpl implements IGwjAttachmentConfigService {
    @Autowired
    private GwjAttachmentConfigMapper gwjAttachmentConfigMapper;

    /**
     * 查询附件配置
     *
     * @param id 附件配置主键
     * @return 附件配置
     */
    @Override
    public GwjAttachmentConfig selectGwjAttachmentConfigById(Long id) {
        return gwjAttachmentConfigMapper.selectGwjAttachmentConfigById(id);
    }

    /**
     * 查询附件配置列表
     *
     * @param gwjAttachmentConfig 附件配置
     * @return 附件配置
     */
    @Override
    public List<GwjAttachmentConfig> selectGwjAttachmentConfigList(GwjAttachmentConfig gwjAttachmentConfig) {
        return gwjAttachmentConfigMapper.selectGwjAttachmentConfigList(gwjAttachmentConfig);
    }

    /**
     * 新增附件配置
     *
     * @param request@return 结果
     */
    @Override
    public int insertGwjAttachmentConfig(GwjAttachmentConfigRequest request) {
        GwjAttachmentConfig bean = BeanUtil.copyProperties(request, GwjAttachmentConfig.class);
        bean.setServerIdentification(IdUtil.getSnowflakeNextIdStr());
        bean.setCreateBy(SecurityUtils.getUsername());
        return gwjAttachmentConfigMapper.insertBatch(bean, request.getTypes());
    }

    /**
     * 修改附件配置
     *
     * @param request 附件配置
     * @return 结果
     */
    @Override
    public int updateGwjAttachmentConfig(GwjAttachmentConfigRequest request) {
        GwjAttachmentConfig bean = BeanUtil.copyProperties(request, GwjAttachmentConfig.class);
        bean.setType(request.getTypes().get(0));
        bean.setUpdateBy(SecurityUtils.getUsername());
        bean.setUpdateTime(DateUtils.getNowDate());
        return gwjAttachmentConfigMapper.updateGwjAttachmentConfig(bean);
    }

    /**
     * 批量删除附件配置
     *
     * @param ids 需要删除的附件配置主键
     * @return 结果
     */
    @Override
    public int deleteGwjAttachmentConfigByIds(Long[] ids) {
        return gwjAttachmentConfigMapper.deleteGwjAttachmentConfigByIds(ids);
    }

    /**
     * 删除附件配置信息
     *
     * @param id 附件配置主键
     * @return 结果
     */
    @Override
    public int deleteGwjAttachmentConfigById(Long id) {
        return gwjAttachmentConfigMapper.deleteGwjAttachmentConfigById(id);
    }

    @Override
    public List<GwjAttachmentConfigDTO> list(GwjAttachmentConfig gwjAttachmentConfig) {
        return gwjAttachmentConfigMapper.list(gwjAttachmentConfig);
    }
}
